<?php

/*
    Author: Mike
    Date:2013/06/17
*/

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');


//企业订单列表
/*
if ($_REQUEST['act'] == 'list')
{
    $company_list = get_company_order_list();

    $smarty->assign('company_list',  $company_list);
    
    $smarty->display('company_order.htm');
}
*/


if ($_REQUEST['act'] == 'list')
{
	if(admin_priv('view_company_order')==false){
	    ecs_header("Location: $url\n");
	    exit;
	}
	
    $smarty->assign('full_page',    1);
    $company_list = get_company_order_list();
    $smarty->assign('company_list',   $company_list['company']);
    $smarty->assign('filter',       $company_list['filter']);
    $smarty->assign('record_count', $company_list['record_count']);
    $smarty->assign('page_count',   $company_list['page_count']);
    
    $smarty->display('company_order.htm');
}
elseif ($_REQUEST['act'] == 'query')
{
    $company_list = get_company_order_list();
    $smarty->assign('company_list',   $company_list['company']);
    $smarty->assign('filter',       $company_list['filter']);
    $smarty->assign('record_count', $company_list['record_count']);
    $smarty->assign('page_count',   $company_list['page_count']);

    make_json_result($smarty->fetch('company_order.htm'), '',
        array('filter' => $company_list['filter'], 'page_count' => $company_list['page_count']));
}

elseif ($_REQUEST['act'] == 'remove')
{

    $id = intval($_GET['id']);

    $db->query("DELETE from hgs_company_order WHERE id=$id");
    
    $url = 'company_order.php?act=query&' . str_replace('act=remove', '', $_SERVER['QUERY_STRING']);

    ecs_header("Location: $url\n");
    exit;
}

elseif($_REQUEST['act'] == 'edit')
{
    echo "编辑";
}

//获取企业订单列表
function get_company_order_list()
{
    $result = get_filter();
    if ($result === false)
    {
        /* 分页大小 */
        $filter = array();

        /* 记录总数以及页数 */
        $count = "SELECT count(id) FROM " .$GLOBALS['ecs']->table('company_order');
        $sql = "SELECT * FROM `hgs_company_order` ORDER BY id DESC ";

        $filter['record_count'] = $GLOBALS['db']->getOne($count);

        $filter = page_and_size($filter);

        set_filter($filter, $sql);
    }
    else
    {
        $sql    = $result['sql'];
        $filter = $result['filter'];
    }
    $res = $GLOBALS['db']->selectLimit($sql, $filter['page_size'], $filter['start']);

    $arr = array();
    while ($rows = $GLOBALS['db']->fetchRow($res))
    {
        $arr[] = $rows;
    }

    return array('company' => $arr, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
    
}





/*
function get_company_order_list()
{
    $sql = "SELECT * FROM `hgs_company_order` ORDER BY id DESC ";
    $query=mysql_query($sql);

    $arr=array();
    while($rows=mysql_fetch_array($query))
    {
        $arr[]=$rows;
    }

    return $arr;
}
*/
?>